package com.ruoyi.web.service.impl;

import com.gitee.deeround.jdbchelper.DbAction;
import com.ruoyi.web.service.SysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysConfigServiceImpl implements SysConfigService {

    @Autowired
    private DbAction dbAction;

    @Override
    public Object getValueByKey(String key) {
        return dbAction.queryForValue("select config_value from sys_config where config_key=?", key);
    }

    @Override
    public Integer getIntegerValueByKey(String key, int defaultValue) {
        Object value = getValueByKey(key);
        if (value == null) {
            return defaultValue;
        }
        return Integer.parseInt(value.toString());
    }

    @Override
    public String getStringValueByKey(String key, String defaultValue) {
        Object value = getValueByKey(key);
        if (value == null) {
            return defaultValue;
        }
        return value.toString();
    }
}
